<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", -1); //prevents caching at the proxy server
%>
<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"%>
<% int validaSession = 2; %>
<%@ include file="Connections/session.jsp" %>
<%@ include file="Connections/conDB.jsp" %>
<%
String parModalidad = request.getParameter("modalidad");
String parId_demora=request.getParameter("id_Demora");
String parFecha_dem=request.getParameter("fechaDemora");
String parId_unid=request.getParameter("id_Unidad");
String parHora_dem=request.getParameter("HoraDemora");
String parLugar=request.getParameter("Lugar");
String parMotivo=request.getParameter("MotivoDemora");
String parObservaciones=request.getParameter("observaciones");
//---------------
	String anio = "";
	String mes = "";
	String dia = "";
	int inicio = 0;
	int fin = 0;
	fin = parFecha_dem.indexOf("/",inicio);
	dia = parFecha_dem.substring(inicio,fin);
	inicio = fin +1;
	fin = parFecha_dem.indexOf("/",inicio);
	mes = parFecha_dem.substring(inicio,fin);
	inicio = fin +1;
	anio = parFecha_dem.substring(inicio,parFecha_dem.length());
//------------
	parFecha_dem = mes+"/"+dia+"/"+anio;
//-------

Driver DriverRs = (Driver)Class.forName(MM_conDB_DRIVER).newInstance();
Connection ConnRs = DriverManager.getConnection(MM_conDB_STRING,MM_conDB_USERNAME,MM_conDB_PASSWORD);
String query ="";
PreparedStatement StatementRs =null;

//if (parId_unid!=null && !parId_unid.equals("") && parId_demora!=null && !parId_demora.equals("")) {
	
if(parModalidad!=null && parModalidad.equals("nuevo") && parId_unid!=null && !parId_unid.equals("")){	
	query="INSERT INTO demora (fecha,horas,lugar,motivo,observaciones,unidad) VALUES "+
			"('"+parFecha_dem+"','"+parHora_dem+"','"+parLugar+"','"+parMotivo+"','"+parObservaciones+"',"+parId_unid+")";
	//out.print(query);
	StatementRs = ConnRs.prepareStatement(query);
	StatementRs.executeUpdate(); 
}

if(parModalidad!=null && parModalidad.equals("modificar") && parId_unid!=null && !parId_unid.equals("") && parId_demora!=null && !parId_demora.equals("")){
	query = "UPDATE demora SET "+
			"fecha = '"+parFecha_dem+"',horas = '"+parHora_dem+"',lugar = '"+parLugar+"',motivo = '"+parMotivo+"', observaciones = '"+parObservaciones+"' "+
			"WHERE id_demora = "+parId_demora; 
	//out.print(query);
	StatementRs = ConnRs.prepareStatement(query);
	StatementRs.executeUpdate(); 

}

		out.print("<script>");
		out.print("window.opener.location.reload();");
		out.print("window.close();");
		out.print("</script>");

ConnRs.close();
%>
<html>
<head>
<title>CIMA v2 - Guardar Captura Demora</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

</body>
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
